package com.funtonow.jqdk.ui;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.funtonow.jqdk.R;
import com.funtonow.jqdk.adapter.UserCheckboxAdapter;
import com.funtonow.jqdk.base.BaseActivity;
import com.funtonow.jqdk.base.BaseBean;
import com.funtonow.jqdk.base.Constants;
import com.funtonow.jqdk.bean.CityJsonBean;
import com.funtonow.jqdk.bean.DataStringBean;
import com.funtonow.jqdk.bean.IdCardAndBankInfo;
import com.funtonow.jqdk.bean.UserInfoBean;
import com.funtonow.jqdk.event.UserInfoEvent;
import com.funtonow.jqdk.fkcs.ui.CardActivity;
import com.funtonow.jqdk.fkcs.ui.DkFailActivity;
import com.funtonow.jqdk.utils.AppUtils;
import com.funtonow.jqdk.utils.FileUtils;
import com.funtonow.jqdk.utils.HttpUtil;
import com.funtonow.jqdk.utils.LogUtil;
import com.funtonow.jqdk.utils.SPUtil;
import com.funtonow.jqdk.utils.StringUtil;
import com.funtonow.jqdk.utils.ToastUtils;
import com.funtonow.jqdk.utils.UiUtils;
import com.funtonow.jqdk.widget.ProgressDialogUtil;
import com.xinyan.bigdata.XinYanSDK;
import com.xinyan.bigdata.bean.StartParams;
import com.xinyan.bigdata.bean.TitleConfig;
import com.xinyan.bigdata.bean.XinyanCallBackData;
import com.xinyan.bigdata.callback.XYBDResultCallback;

import org.greenrobot.eventbus.EventBus;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;

import butterknife.BindView;
import butterknife.OnClick;
import okhttp3.Call;

import static com.funtonow.jqdk.base.UrlUtils.TX;
import static com.funtonow.jqdk.base.UrlUtils.UPDATE;
import static com.funtonow.jqdk.base.UrlUtils.XY_YYS;

/**
 * @author Jiajien
 * @date 2019/6/21
 */
public class UserInfoActivity extends BaseActivity implements View.OnClickListener {

    @BindView(R.id.et_name)
    EditText etName;
    @BindView(R.id.et_card_id)
    EditText etCardId;
    @BindView(R.id.tv_marital_status)
    TextView mTvMaritalStatus;
    @BindView(R.id.tv_education_level)
    TextView mTvEducationLevel;
    @BindView(R.id.tv_work)
    TextView mTvWork;
    @BindView(R.id.et_address)
    EditText mEtAddress;
    @BindView(R.id.tv_income)
    TextView mTvIncome;
    @BindView(R.id.rlv_fixed_assets)
    RecyclerView rlvFixedAssets;
    @BindView(R.id.rlv_hobby)
    RecyclerView rlvHobby;
    @BindView(R.id.tv_address)
    TextView tvAdress;
    @BindView(R.id.iv_sub)
    Button ivSub;
    @BindView(R.id.ll_contacts)
    LinearLayout llContacts;
    @BindView(R.id.et_contacts_phone1)
    EditText etContactsPhone1;
    @BindView(R.id.et_contacts1)
    EditText etContacts1;
    @BindView(R.id.et_contacts_phone)
    EditText etContactsPhone;
    @BindView(R.id.et_contacts)
    EditText etContacts;
    @BindView(R.id.tv_gx)
    TextView tvGx;
    @BindView(R.id.tv_gx1)
    TextView tvGx1;
    @BindView(R.id.btn_phone_yz)
    Button btnPhoneYz;

    private Intent intent;
    private int hun;
    private UserInfoBean userInfoBean;
    private UserCheckboxAdapter userCheckboxAdapter;
    private UserCheckboxAdapter hobbyAdapter;
    private String fixedAssets; // 收入
    private List<String> hobbyList;
    private int isSub;

    private List<CityJsonBean> options1Items = new ArrayList<>();
    private ArrayList<ArrayList<String>> options2Items = new ArrayList<>();
    private ArrayList<ArrayList<ArrayList<String>>> options3Items = new ArrayList<>();

    private boolean isSubInfo = false;


    @Override
    public int getLayoutRes() {
        return R.layout.activity_user_info;
    }

    @Override
    public void onCreateActivity(@Nullable Bundle savedInstanceState) {
        initToolbar(getResources().getString(R.string.title_user_info));
        getCityJson();
        initReclyView(rlvFixedAssets);
        initReclyView(rlvHobby);
        userCheckboxAdapter = new UserCheckboxAdapter();
        rlvFixedAssets.setAdapter(userCheckboxAdapter);
        hobbyAdapter = new UserCheckboxAdapter();
        rlvHobby.setAdapter(hobbyAdapter);
        initData();
//        if (AppUtils.getAppName(this).equals(getResources().getString(R.string.ssq_app_name))) {
//            llContacts.setVisibility(View.VISIBLE);
//        } else {
//            llContacts.setVisibility(View.GONE);
//        }
        etContactsPhone1.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (StringUtil.isEmpty(s.toString())
                        && !StringUtil.isEmpty(etName.getText().toString())
                        && !StringUtil.isEmpty(etContacts.getText().toString())
                        && !StringUtil.isEmpty(etContacts1.getText().toString())
                        && !StringUtil.isEmpty(etContactsPhone.getText().toString())
                        && !StringUtil.isLegalId(etCardId.getText().toString())) {
                    btnPhoneYz.setBackgroundResource(R.drawable.btn_blue_layout);
                    btnPhoneYz.setEnabled(true);
                } else {
                    ToastUtils.show("请填写完整信息");
                }
            }
        });
        userCheckboxAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                List<DataStringBean> dataStringBeans = userCheckboxAdapter.getData();
                for (int i = 0; i < dataStringBeans.size(); i++) {
                    DataStringBean dataStringBean = dataStringBeans.get(i);
                    if (i == position) {
                        dataStringBean.setCheckbox(true);
                        fixedAssets = dataStringBean.getName();
                    } else {
                        dataStringBean.setCheckbox(false);
                    }
                    userCheckboxAdapter.setData(i, dataStringBean);
                }
            }
        });

        hobbyAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                CheckBox checkBox = view.findViewById(R.id.checkbox);
                DataStringBean citiesBean = hobbyAdapter.getData().get(position);
                if (hobbyList == null) {
                    hobbyList = new ArrayList<>();
                }
                if (hobbyList.size() >= 3 && !citiesBean.isCheckbox()) {
                    ToastUtils.show("最多选择3个爱好");
                } else {
                    if (citiesBean.isCheckbox()) {
                        citiesBean.setCheckbox(false);
                        checkBox.setChecked(false);
                        hobbyList.remove(citiesBean.getName());
                    } else {
                        hobbyList.add(citiesBean.getName());
                        citiesBean.setCheckbox(true);
                        checkBox.setChecked(true);
                    }
                }
            }
        });

        if (AppUtils.getAppName(this).equals(getString(R.string.ssq_app_name))) {
            ivSub.setText("下一步");
            mTvSave.setVisibility(View.GONE);
        } else {
            mTvSave.setVisibility(View.VISIBLE);
            ivSub.setText("提交");
        }

    }

    private void initData() {
        userInfoBean = SPUtil.getUserInfo();
        assert userInfoBean != null;
        if (userInfoBean.getHun() == 1) {
            mTvMaritalStatus.setText("未婚");
        } else if (userInfoBean.getHun() == 2) {
            mTvMaritalStatus.setText("已婚");
        } else if (userInfoBean.getHun() == 3) {
            mTvMaritalStatus.setText("离异");
        }
        if (!StringUtil.isEmpty(userInfoBean.getEdu())) {
            mTvEducationLevel.setText(userInfoBean.getEdu());
        }
        if (!StringUtil.isEmpty(userInfoBean.getZy())) {
            mTvWork.setText(userInfoBean.getZy());
        }
        if (userInfoBean.getDetail() != null) {
            if (userInfoBean.getDetail().getConstants() != null && userInfoBean.getDetail().getConstants1() != null) {
                if (!StringUtil.isEmpty(userInfoBean.getDetail().getConstants().getName())) {
                    etContacts.setText(userInfoBean.getDetail().getConstants().getName());
                }

                if (!StringUtil.isEmpty(userInfoBean.getDetail().getConstants1().getName())) {
                    etContacts1.setText(userInfoBean.getDetail().getConstants1().getName());
                }

                if (!StringUtil.isEmpty(userInfoBean.getDetail().getConstants().getPhone())) {
                    etContactsPhone.setText(userInfoBean.getDetail().getConstants().getPhone());
                }

                if (!StringUtil.isEmpty(userInfoBean.getDetail().getConstants1().getPhone())) {
                    etContactsPhone1.setText(userInfoBean.getDetail().getConstants1().getPhone());
                }

                if (!StringUtil.isEmpty(userInfoBean.getDetail().getConstants().getGx())) {
                    tvGx.setText(userInfoBean.getDetail().getConstants().getGx());
                }

                if (!StringUtil.isEmpty(userInfoBean.getDetail().getConstants1().getGx())) {
                    tvGx1.setText(userInfoBean.getDetail().getConstants1().getGx());
                }
            }
        }
        if (!StringUtil.isEmpty(userInfoBean.getAdress())) {
            if (userInfoBean.getAdress().split(",").length > 2) {
                tvAdress.setText(userInfoBean.getAdress().split(",")[0]);
                mEtAddress.setText(userInfoBean.getAdress().split(",")[1]);
            } else {
                tvAdress.setText(userInfoBean.getAdress().split(",")[0]);
            }
        }
        if (!StringUtil.isEmpty(userInfoBean.getShouru())) {
            mTvIncome.setText(userInfoBean.getShouru());
        }


        if (!StringUtil.isEmpty(userInfoBean.getNickname()) && !StringUtil.isEmpty(userInfoBean.getShenfenz())) {
            etName.setFocusable(false);
            etCardId.setFocusable(false);
            etName.setText(userInfoBean.getNickname());
            etCardId.setText(userInfoBean.getShenfenz());
        }

//        if (StringUtil.isEmpty(userInfoBean.getDetail().getPhone())
//                && !StringUtil.isEmpty(userInfoBean.getNickname())
//                && !StringUtil.isEmpty(userInfoBean.getDetail().getConstants().getName())
//                && !StringUtil.isEmpty(userInfoBean.getDetail().getConstants1().getName())
//                && !StringUtil.isEmpty(userInfoBean.getDetail().getConstants1().getPhone())
//                && !StringUtil.isLegalId(userInfoBean.getShenfenz())) {
//            btnPhoneYz.setBackgroundResource(R.drawable.btn_blue_layout);
//            btnPhoneYz.setEnabled(true);
//        }

        if (!StringUtil.isEmpty(userInfoBean.getZichan())) {
            fixedAssets = userInfoBean.getZichan();
            userCheckboxAdapter.setNewData(dataString("fixed_assets", userInfoBean.getZichan().split(",")));
        } else {
            userCheckboxAdapter.setNewData(dataString("fixed_assets", new String[0]));
        }
        if (!StringUtil.isEmpty(userInfoBean.getAihao())) {
            List<String> list = Arrays.asList(userInfoBean.getAihao().split(","));
            hobbyList = new ArrayList<>(list);
            hobbyAdapter.setNewData(dataString("hobby", userInfoBean.getAihao().split(",")));
        } else {
            hobbyAdapter.setNewData(dataString("hobby", new String[0]));
        }
    }


    @OnClick({R.id.tv_marital_status, R.id.tv_education_level, R.id.iv_sub,
            R.id.tv_work, R.id.rl_fixed_assets, R.id.tv_income, R.id.tv_address,
            R.id.tv_save, R.id.btn_phone_yz, R.id.tv_gx, R.id.tv_gx1})
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_marital_status:
                intent = new Intent(this, SelectStringActivity.class);
                intent.putExtra("key", Constants.SELECT_MARITAL_STATUS);
                intent.putExtra("title", getResources().getString(R.string.select_marital_status));
                startActivityForResult(intent, Constants.SELECT_MARITAL_STATUS_CODE);
                break;
            case R.id.tv_education_level:
                intent = new Intent(this, SelectStringActivity.class);
                intent.putExtra("key", Constants.SELECT_DEUCATION_LEVEL);
                intent.putExtra("title", getResources().getString(R.string.select_education_level));
                startActivityForResult(intent, Constants.SELECT_EDUCATION_LEVEL_CODE);
                break;
            case R.id.tv_work:
                intent = new Intent(this, SelectStringActivity.class);
                intent.putExtra("key", Constants.SELECT_WORK);
                intent.putExtra("title", getResources().getString(R.string.select_work));
                startActivityForResult(intent, Constants.SELECT_WORK_CODE);
                break;
            case R.id.tv_income:
                intent = new Intent(this, SelectStringActivity.class);
                intent.putExtra("key", Constants.SELECT_INCOME);
                intent.putExtra("title", getResources().getString(R.string.select_income));
                startActivityForResult(intent, Constants.SELECT_INCOME_CODE);
                break;
            case R.id.rl_fixed_assets:
                intent = new Intent(this, SelectStringActivity.class);
                intent.putExtra("key", Constants.SELECT_FIXED_ASSETS);
                intent.putExtra("title", getResources().getString(R.string.select_fixed_assets));
                startActivityForResult(intent, Constants.SELECT_FIXED_ASSETS_CODE);
                break;
            case R.id.iv_sub:
                isSub = 1;
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
                Date date = new Date(System.currentTimeMillis());
                SPUtil.put("isShowInfo", simpleDateFormat.format(date));
                updateInfo();
                break;
            case R.id.tv_save:
                isSub = 0;
                updateInfo();
                break;
            case R.id.tv_address:
                showPickerView();
                break;
            case R.id.tv_gx:
                intent = new Intent(this, SelectStringActivity.class);
                intent.putExtra("key", Constants.SELECT_RELATION);
                intent.putExtra("title", getResources().getString(R.string.select_fixed_assets));
                startActivityForResult(intent, Constants.SELECT_RELATION_CODE);
                break;
            case R.id.tv_gx1:
                intent = new Intent(this, SelectStringActivity.class);
                intent.putExtra("key", Constants.SELECT_RELATION);
                intent.putExtra("title", getResources().getString(R.string.select_fixed_assets));
                startActivityForResult(intent, Constants.SELECT_RELATION_CODE1);
                break;
            case R.id.btn_phone_yz:
                StartParams startParams = new StartParams();
                startParams.setType("carrier");
                startParams.setRealname(etName.getText().toString());
                startParams.setIdcard(etCardId.getText().toString());
                startParams.setPhoneNum(userInfoBean.getOpenid());
                startParams.setTitleConfig(new TitleConfig());
                startParams.setTaskId(UiUtils.getUUID32());//TODO    小于32  唯一字符串
                XinYanSDK.getInstance().start(this, startParams, new XYBDResultCallback() {
                    @Override
                    public void onCallBack(XinyanCallBackData xinyanCallBackData) {
                        //XinyanCallBackData 参数说明
                        // code (成功code 1  其他失败)
                        // taskType (任务类型)
                        // token (任务凭证 查询报告)
                        // message （返回信息）
                        LogUtil.i(JSON.toJSONString(xinyanCallBackData) + "  **********  ");
                        if (xinyanCallBackData.getCode() == 1) {
                            setXyYss(xinyanCallBackData.getToken());
                        } else {
                            ToastUtils.show(xinyanCallBackData.getMessage());
                        }

                    }

                    @Override
                    public void onError(Throwable throwable) {

                    }
                });
                break;
            default:
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            assert data != null;
            Bundle bundle = data.getExtras();
            assert bundle != null;
            switch (requestCode) {
                case Constants.SELECT_MARITAL_STATUS_CODE:
                    if (Objects.equals(bundle.getString("result"), "未婚")) {
                        hun = 0;
                    } else if (Objects.equals(bundle.getString("result"), "已婚")) {
                        hun = 1;
                    } else {
                        hun = 2;
                    }
                    mTvMaritalStatus.setText(bundle.getString("result"));
                    break;
                case Constants.SELECT_EDUCATION_LEVEL_CODE:
                    mTvEducationLevel.setText(bundle.getString("result"));
                    break;
                case Constants.SELECT_WORK_CODE:
                    mTvWork.setText(bundle.getString("result"));
                    break;
                case Constants.SELECT_INCOME_CODE:
                    mTvIncome.setText(bundle.getString("result"));
                    break;
                case Constants.SELECT_RELATION_CODE:
                    tvGx.setText(bundle.getString("result"));
                    break;
                case Constants.SELECT_RELATION_CODE1:
                    tvGx1.setText(bundle.getString("result"));
                    break;
                default:
                    break;
            }
        }
    }

    public void updateInfo() {
        ProgressDialogUtil.startProgressDialog(this);
        UserInfoBean userInfoBean = SPUtil.getUserInfo();
        Map<String, String> param = new HashMap<>();
        assert userInfoBean != null;
        param.put("appid", Constants.OWN_APP_ID);
        param.put("token", userInfoBean.getToken());
        param.put("openid", userInfoBean.getOpenid());
        param.put("tj", String.valueOf(isSub));
        if (!StringUtil.isEmpty(userInfoBean.getAvatarUrl())) {
            param.put("head", userInfoBean.getAvatarUrl());
        }
        if (!StringUtil.isEmpty(mTvMaritalStatus.getText().toString())) {
            param.put("hun", String.valueOf(hun));
        }
        if (!StringUtil.isEmpty(mTvEducationLevel.getText().toString())) {
            param.put("edu", mTvEducationLevel.getText().toString());
        }
        if (!StringUtil.isEmpty(mTvWork.getText().toString())) {
            param.put("zy", mTvWork.getText().toString());
        }
        if (!StringUtil.isEmpty(mEtAddress.getText().toString()) && !StringUtil.isEmpty(tvAdress.getText().toString())) {
            param.put("adress", tvAdress.getText().toString() + "," + mEtAddress.getText().toString());
        }
        if (!StringUtil.isEmpty(mTvIncome.getText().toString())) {
            param.put("shouru", mTvIncome.getText().toString());
        }
        if (!StringUtil.isEmpty(fixedAssets)) {
            param.put("zichan", fixedAssets);
        }
        param.put("sfz", etCardId.getText().toString());
        param.put("name", etName.getText().toString());
        IdCardAndBankInfo idCardAndBankInfo = userInfoBean.getDetail();
        idCardAndBankInfo.setFlag("1");
        IdCardAndBankInfo.Constants constants = new IdCardAndBankInfo.Constants();
        constants.setName(etContacts.getText().toString());
        constants.setPhone(etContactsPhone.getText().toString());
        constants.setGx(tvGx.getText().toString());
        IdCardAndBankInfo.Constants constants1 = new IdCardAndBankInfo.Constants();
        constants.setName(etContacts1.getText().toString());
        constants.setPhone(etContactsPhone1.getText().toString());
        constants.setGx(tvGx1.getText().toString());
        idCardAndBankInfo.setConstants(constants);
        idCardAndBankInfo.setConstants1(constants1);
        param.put("detail", JSON.toJSONString(idCardAndBankInfo));
        StringBuilder result = new StringBuilder();
        if (hobbyList != null && hobbyList.size() > 0) {
            for (String item : hobbyList) {
                result.append(item).append(",");
            }
            result.deleteCharAt(result.length() - 1);
            param.put("aihao", result.toString());
        }
        HttpUtil.getInstance().postDataAsynToNet(UPDATE, param, new HttpUtil.MyNetCall() {
            @Override
            public void success(Call call, String jsonString) throws IOException {
                ProgressDialogUtil.stopProgressDialog();
                BaseBean baseBean = JSON.parseObject(jsonString, BaseBean.class);
                if (baseBean.errnum == 0) {
                    SPUtil.put("userInfo", baseBean.data);
                    ToastUtils.show("保存成功");
                    EventBus.getDefault().post(new UserInfoEvent());
                    if (AppUtils.getAppName(UserInfoActivity.this).equals(getString(R.string.ssq_app_name))) {
                        startActivity(new Intent(UserInfoActivity.this, DkFailActivity.class));
                    } else {
                        startActivity(new Intent(UserInfoActivity.this, CardActivity.class));
                    }
                    finish();
                }
            }

            @Override
            public void failed(Call call, IOException e) {

            }
        });
    }


    /**
     * 得到选择数据
     *
     * @param key
     * @return
     */
    private List<DataStringBean> dataString(String key, String[] strings) {
        List<DataStringBean> dataStringBeans = new ArrayList<>();
        String dataJson = FileUtils.getJson(this, "baseData.json");
        JSONArray jsonArray = JSON.parseObject(dataJson).getJSONArray(key);
        List<String> dataStringBeanList = JSON.parseArray(jsonArray.toJSONString(), String.class);
        for (String s : dataStringBeanList) {
            DataStringBean dataStringBean = new DataStringBean();
            dataStringBean.setName(s);
            dataStringBean.setCheckbox(false);
            dataStringBeans.add(dataStringBean);
        }
        if (strings.length > 0) {
            for (int i = 0; i < dataStringBeans.size(); i++) {
                DataStringBean dataStringBean = dataStringBeans.get(i);
                for (String s : strings) {
                    if (s.equals(dataStringBean.getName())) {
                        dataStringBean.setCheckbox(true);
                        dataStringBeans.set(i, dataStringBean);
                    }
                }
            }
        }
        return dataStringBeans;
    }

    /**
     * 设置 RecyclerView
     *
     * @param recyclerView
     */
    private void initReclyView(RecyclerView recyclerView) {
        GridLayoutManager layoutManager = new GridLayoutManager(this, 4);
        recyclerView.setLayoutManager(layoutManager);
    }

    /**
     * 获得json数据
     */
    public void getCityJson() {
        String jsonString = FileUtils.getJson(this, "province.json");
        List<CityJsonBean> cityJsonBeans = JSON.parseArray(jsonString, CityJsonBean.class);
        options1Items = cityJsonBeans;

        for (int i = 0; i < cityJsonBeans.size(); i++) {//遍历省份
            ArrayList<String> cityList = new ArrayList<>();//该省的城市列表（第二级）
            ArrayList<ArrayList<String>> province_AreaList = new ArrayList<>();//该省的所有地区列表（第三极）

            for (int c = 0; c < cityJsonBeans.get(i).getCity().size(); c++) {//遍历该省份的所有城市
                String cityName = cityJsonBeans.get(i).getCity().get(c).getName();
                cityList.add(cityName);//添加城市
                ArrayList<String> city_AreaList = new ArrayList<>();//该城市的所有地区列表
                city_AreaList.addAll(cityJsonBeans.get(i).getCity().get(c).getArea());
                province_AreaList.add(city_AreaList);//添加该省所有地区数据
            }

            /**
             * 添加城市数据
             */
            options2Items.add(cityList);

            /**
             * 添加地区数据
             */
            options3Items.add(province_AreaList);
        }

    }

    private void showPickerView() {// 弹出选择器

        OptionsPickerView pvOptions = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                //返回的分别是三个级别的选中位置
                String opt1tx = options1Items.size() > 0 ?
                        options1Items.get(options1).getPickerViewText() : "";

                String opt2tx = options2Items.size() > 0
                        && options2Items.get(options1).size() > 0 ?
                        options2Items.get(options1).get(options2) : "";

                String opt3tx = options2Items.size() > 0
                        && options3Items.get(options1).size() > 0
                        && options3Items.get(options1).get(options2).size() > 0 ?
                        options3Items.get(options1).get(options2).get(options3) : "";

                String tx = opt1tx + opt2tx + opt3tx;
                tvAdress.setText(tx);
            }
        })

                .setTitleText("城市选择")
                .setDividerColor(Color.BLACK)
                .setTextColorCenter(Color.BLACK) //设置选中项文字颜色
                .setContentTextSize(20)
                .build();

        /*pvOptions.setPicker(options1Items);//一级选择器
        pvOptions.setPicker(options1Items, options2Items);//二级选择器*/
        pvOptions.setPicker(options1Items, options2Items, options3Items);//三级选择器
        pvOptions.show();
    }

    private void setXyYss(String xyToken) {
        UserInfoBean userInfoBean = SPUtil.getUserInfo();
        Map<String, String> param = new HashMap<>();
        assert userInfoBean != null;
        param.put("appid", Constants.OWN_APP_ID);
        param.put("token", userInfoBean.getToken());
        param.put("openid", userInfoBean.getOpenid());
        param.put("xytoken", xyToken);
        HttpUtil.getInstance().postDataAsynToNet(XY_YYS, param, new HttpUtil.MyNetCall() {
            @Override
            public void success(Call call, String jsonString) throws IOException {
                LogUtil.i(jsonString + " ***********  ");
                isSubInfo = true;
                ivSub.setBackgroundResource(R.drawable.btn_blue_layout);
                ivSub.setEnabled(true);
            }

            @Override
            public void failed(Call call, IOException e) {

            }
        });
    }

}
